<template>
  <div class="app-container">

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd()"
        >新增看板
        </el-button>
      </el-col>
    </el-row>

    <el-table
      v-loading="loading"
      :data="categoryList"
      @cell-click="cellclick"
    >
      <el-table-column label="ID" align="center" prop="id"/>
      <el-table-column label="看板名称" align="center" prop="name"/>
      <el-table-column label="描述" align="center" prop="description"/>
      <el-table-column label="组件数量" align="center" prop="number"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-date"
            @click="showBoardBox(scope.row)"
            v-hasPermi="['system:category:edit']"
          >看板信息
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:category:edit']"
          >编辑看板
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:category:remove']"
          >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <dataBoard :visible.sync="dataBoardVisible" :detailId="detailId"></dataBoard>
    <addBoard :visible.sync="detailVisible" :detailId="detailId" @getList="getList"></addBoard>
  </div>
</template>

<script>
import {panelList, panelDelete} from '@/api/system/board'
import dataBoard from "./dataBoard";
import addBoard from "./components/addBoard";

export default {
  name: "Category",
  components: {dataBoard, addBoard},
  data() {
    return {
      detailVisible: false,
      detailId: 0,
      dataBoardVisible: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 子表选中数据
      checkedCategoryDataConfig: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示search条件
      showSearch: true,
      // 总条数
      total: 0,
      // 设备分类表格数据
      categoryList: [],
      // 类别数据配置表格数据
      categoryDataConfigList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      cateVisible: false,
      cateId: 0,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
        orderNum: null,
        deviceColum: null
      },
      // 表单参数
      form: {},
      // 表单校验
      options: [{
        value: 'switch',
        label: 'Switch'
      }, {
        value: 'number',
        label: 'Number',
      }, {
        value: 'text',
        label: 'String'
      }],
      selectvalue: [
        {
          value: 'true/flase',
          label: 'true/flase'
        },
        {
          value: '1/0',
          label: '1/0'
        },
        {
          value: 'ON/OF',
          label: 'ON/OF'
        },
      ],
      value: '',
      downData: []
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询设备分类列表 */
    getList() {
      this.loading = true;
      panelList(this.queryParams).then(response => {
        this.categoryList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 表单reset
    reset() {
      this.form = {
        id: null,
        name: null,
        createTime: null,
        orderNum: null,
        deviceColum: null,
        pushTopic: '',
        subTopic: '',
      };
      this.categoryDataConfigList = [];
      this.resetForm("form");
    },
    /** search按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** reset按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** add按钮操作 */
    handleAdd() {
      this.detailId = 0
      this.detailVisible = true
    },
    /** edit按钮操作 */
    handleUpdate(row) {
      this.detailId = row.id
      this.detailVisible = true
    },
    /** delete按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('Are you sure to delete the data item for rule '+ids+'？').then(function () {
        return panelDelete(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("success");
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/category/export', {
        ...this.queryParams
      }, `category_${new Date().getTime()}.xlsx`)
    },
    cellclick(row, column, cell, event) {
      if (column.label !== 'operation') {
        this.showBoardBox(row)
      }
    },
    showBoardBox(row) {
      this.detailId = row.id
      this.dataBoardVisible = true
    }
  }
};
</script>
<style>
.detel-line-index {
  color: #ed5565;
  font-size: 18px;
  font-weight: bold;
  cursor: pointer;
}
</style>
